package name.wilbur.course.db.bigone.service.impl;

import name.wilbur.course.db.bigone.dao.DAOFactory;
import name.wilbur.course.db.bigone.dao.impl.IUserDAO;
import name.wilbur.course.db.bigone.dao.impl.UserDAO;
import name.wilbur.course.db.bigone.model.User;
import name.wilbur.course.db.bigone.service.IRegisterService;
import name.wilbur.course.db.bigone.util.Checker;

public class RegisterService implements IRegisterService {
	private IUserDAO userDAO;
	
	public RegisterService() {
	}
	
	public boolean addUser(String name, String pass, String email, boolean admin) {
		boolean ok = false;
		User user = null;
		if (Checker.notEmptyString(name) && Checker.notEmptyString(pass)) {
			user = new User(name, pass, email, admin);
			ok = getUserDAO().create(user);
		}
		return ok;
	}
	
	public IUserDAO getUserDAO() {
		if (userDAO == null)
			userDAO = (UserDAO) DAOFactory.createDAO(UserDAO.class);
		return userDAO;
	}
}
